.class Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;
.super Ljava/lang/Object;
.source "ViewPagerAdapter.java"

# interfaces
.implements Ljava/lang/Runnable;


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/opongo/blogapp/adapter/ViewPagerAdapter;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x0
    name = "PostWorker"
.end annotation


# instance fields
.field private p:I

.field final synthetic this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

.field private update:Z


# direct methods
.method public constructor <init>(Lcom/opongo/blogapp/adapter/ViewPagerAdapter;IZ)V
    .locals 1
    .parameter
    .parameter "p"
    .parameter "update"

    .prologue
    .line 381
    iput-object p1, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 382
    iput p2, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->p:I

    .line 383
    iput-boolean p3, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->update:Z

    .line 384
    new-instance v0, Ljava/lang/Thread;

    invoke-direct {v0, p0}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    .line 385
    return-void
.end method


# virtual methods
.method public run()V
    .locals 12

    .prologue
    .line 388
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    #getter for: Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->mAdapterArray:Ljava/util/ArrayList;
    invoke-static {v0}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$0(Lcom/opongo/blogapp/adapter/ViewPagerAdapter;)Ljava/util/ArrayList;

    move-result-object v0

    iget v1, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->p:I

    invoke-virtual {v0, v1}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v8

    check-cast v8, Lcom/opongo/blogapp/adapter/PostListAdapter;

    .line 390
    .local v8, mAdapter:Lcom/opongo/blogapp/adapter/PostListAdapter;
    iget-object v10, v8, Lcom/opongo/blogapp/adapter/PostListAdapter;->posts:Ljava/util/ArrayList;

    .line 392
    .local v10, posts:Ljava/util/ArrayList;,"Ljava/util/ArrayList<Lcom/opongo/blogapp/common/Post;>;"
    if-eqz v10, :cond_1

    .line 395
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    .line 396
    iget-object v1, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v1, v1, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    invoke-virtual {v1}, Lcom/opongo/blogapp/manager/DatabaseManager;->getTableName()Ljava/lang/String;

    move-result-object v1

    iget v2, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->p:I

    .line 395
    invoke-virtual {v0, v1, v2}, Lcom/opongo/blogapp/manager/DatabaseManager;->queryForBlogTypeID(Ljava/lang/String;I)I

    move-result v6

    .line 398
    .local v6, blogTypeID:I
    invoke-static {}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$4()Ljava/lang/String;

    move-result-object v0

    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "SizePosts: "

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v10}, Ljava/util/ArrayList;->size()I

    move-result v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, " blogTypeID:"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    .line 399
    invoke-virtual {v1, v6}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 398
    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 402
    :try_start_0
    invoke-virtual {v10}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v11

    :cond_0
    :goto_0
    invoke-interface {v11}, Ljava/util/Iterator;->hasNext()Z
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result v0

    if-nez v0, :cond_2

    .line 458
    :goto_1
    iget-boolean v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->update:Z

    if-eqz v0, :cond_8

    .line 459
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    invoke-virtual {v0, v6}, Lcom/opongo/blogapp/manager/DatabaseManager;->cleanPosts(I)V

    .line 487
    .end local v6           #blogTypeID:I
    :cond_1
    :goto_2
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    #getter for: Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->activity:Landroid/app/Activity;
    invoke-static {v0}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$3(Lcom/opongo/blogapp/adapter/ViewPagerAdapter;)Landroid/app/Activity;

    move-result-object v0

    new-instance v1, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$UpdateAdapter;

    iget-object v2, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget v3, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->p:I

    invoke-direct {v1, v2, v3}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$UpdateAdapter;-><init>(Lcom/opongo/blogapp/adapter/ViewPagerAdapter;I)V

    invoke-virtual {v0, v1}, Landroid/app/Activity;->runOnUiThread(Ljava/lang/Runnable;)V

    .line 488
    return-void

    .line 402
    .restart local v6       #blogTypeID:I
    :cond_2
    :try_start_1
    invoke-interface {v11}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v9

    check-cast v9, Lcom/opongo/blogapp/common/Post;

    .line 403
    .local v9, post:Lcom/opongo/blogapp/common/Post;
    iget-boolean v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->update:Z

    if-eqz v0, :cond_4

    .line 404
    invoke-virtual {v10, v9}, Ljava/util/ArrayList;->indexOf(Ljava/lang/Object;)I

    move-result v0

    iput v0, v9, Lcom/opongo/blogapp/common/Post;->order:I

    .line 409
    :goto_3
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    iget v1, v9, Lcom/opongo/blogapp/common/Post;->id:I

    int-to-long v1, v1

    invoke-virtual {v0, v1, v2}, Lcom/opongo/blogapp/manager/DatabaseManager;->itemExists(J)Z

    move-result v0

    if-eqz v0, :cond_5

    .line 410
    sget-boolean v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->DEBUG:Z

    if-eqz v0, :cond_3

    .line 411
    invoke-static {}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$4()Ljava/lang/String;

    move-result-object v0

    .line 412
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "Updating item with id "

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 413
    iget v2, v9, Lcom/opongo/blogapp/common/Post;->id:I

    invoke-static {v2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    .line 412
    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 411
    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 414
    :cond_3
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    invoke-virtual {v0, v9}, Lcom/opongo/blogapp/manager/DatabaseManager;->updatePost(Lcom/opongo/blogapp/common/Post;)I

    .line 425
    :goto_4
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    iget v1, v9, Lcom/opongo/blogapp/common/Post;->id:I

    int-to-long v1, v1

    invoke-virtual {v0, v1, v2, v6}, Lcom/opongo/blogapp/manager/DatabaseManager;->itemExists(JI)Z

    move-result v0

    if-nez v0, :cond_7

    .line 426
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    iget v1, v9, Lcom/opongo/blogapp/common/Post;->id:I

    int-to-long v1, v1

    int-to-long v3, v6

    iget v5, v9, Lcom/opongo/blogapp/common/Post;->order:I

    invoke-virtual/range {v0 .. v5}, Lcom/opongo/blogapp/manager/DatabaseManager;->insertPostToBlogtype(JJI)J

    .line 431
    :goto_5
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->post_id:I

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->post_id:I

    iget v1, v9, Lcom/opongo/blogapp/common/Post;->id:I

    if-ne v0, v1, :cond_0

    iget v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->p:I

    if-nez v0, :cond_0

    .line 432
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    invoke-virtual {v10, v9}, Ljava/util/ArrayList;->indexOf(Ljava/lang/Object;)I

    move-result v1

    iput v1, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->positionInDetailView:I
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto/16 :goto_0

    .line 435
    .end local v9           #post:Lcom/opongo/blogapp/common/Post;
    :catch_0
    move-exception v7

    .line 437
    .local v7, e:Ljava/lang/Exception;
    invoke-static {}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$4()Ljava/lang/String;

    move-result-object v0

    const-string v1, "Insert Post Exeption"

    invoke-static {v0, v1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    .line 438
    invoke-static {}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$4()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {v7}, Ljava/lang/Exception;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    goto/16 :goto_1

    .line 406
    .end local v7           #e:Ljava/lang/Exception;
    .restart local v9       #post:Lcom/opongo/blogapp/common/Post;
    :cond_4
    :try_start_2
    invoke-virtual {v10, v9}, Ljava/util/ArrayList;->indexOf(Ljava/lang/Object;)I

    move-result v0

    iget v1, v8, Lcom/opongo/blogapp/adapter/PostListAdapter;->page:I

    mul-int/2addr v0, v1

    iput v0, v9, Lcom/opongo/blogapp/common/Post;->order:I

    goto/16 :goto_3

    .line 417
    :cond_5
    sget-boolean v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->DEBUG:Z

    if-eqz v0, :cond_6

    .line 418
    invoke-static {}, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->access$4()Ljava/lang/String;

    move-result-object v0

    .line 419
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-virtual {v10, v9}, Ljava/util/ArrayList;->indexOf(Ljava/lang/Object;)I

    move-result v2

    invoke-static {v2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 420
    const-string v2, ". Persisting item with id "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    .line 421
    iget v2, v9, Lcom/opongo/blogapp/common/Post;->id:I

    invoke-static {v2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    .line 419
    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 418
    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 422
    :cond_6
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    invoke-virtual {v0, v9}, Lcom/opongo/blogapp/manager/DatabaseManager;->insertPost(Lcom/opongo/blogapp/common/Post;)J

    goto/16 :goto_4

    .line 428
    :cond_7
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    iget v1, v9, Lcom/opongo/blogapp/common/Post;->id:I

    int-to-long v1, v1

    int-to-long v3, v6

    iget v5, v9, Lcom/opongo/blogapp/common/Post;->order:I

    invoke-virtual/range {v0 .. v5}, Lcom/opongo/blogapp/manager/DatabaseManager;->updatePostToBlogtype(JJI)J
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_0

    goto :goto_5

    .line 461
    .end local v9           #post:Lcom/opongo/blogapp/common/Post;
    :cond_8
    iget-object v0, p0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter$PostWorker;->this$0:Lcom/opongo/blogapp/adapter/ViewPagerAdapter;

    iget-object v0, v0, Lcom/opongo/blogapp/adapter/ViewPagerAdapter;->dbManager:Lcom/opongo/blogapp/manager/DatabaseManager;

    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "UPDATE post_blogtype SET newpost = 0 WHERE blogtype_id = "

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 463
    invoke-virtual {v1, v6}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 461
    invoke-virtual {v0, v1}, Lcom/opongo/blogapp/manager/DatabaseManager;->execQuery(Ljava/lang/String;)V

    .line 466
    iget v0, v8, Lcom/opongo/blogapp/adapter/PostListAdapter;->page:I

    add-int/lit8 v0, v0, 0x1

    iput v0, v8, Lcom/opongo/blogapp/adapter/PostListAdapter;->page:I

    goto/16 :goto_2
.end method
